package com.qiezikaka.kaka.ui;

import android.content.Intent;
import android.provider.Settings;
import android.view.View;

import com.qiezikaka.kaka.R;
import com.qiezikaka.kaka.base.BaseActivity;
import com.qiezikaka.kaka.bean.AllBean;
import com.qiezikaka.kaka.databinding.ActivityStyleChoiceAllBinding;
import com.qiezikaka.kaka.ui.bind.BindStoreActivity;
import com.qiezikaka.kaka.ui.single.StyleSingleActivity;

/**
 * 风格选择页面
 */
public class StyleChoiceAllActivity extends BaseActivity<StyleChoiceAllPresenter> implements View.OnClickListener, StyleChoiceAllContract.View {

    ActivityStyleChoiceAllBinding mBinding;
    private StyleChoiceAllPresenter presenter;
    private String androidId;
    private boolean isBindStore = true;

    @Override
    public View getLayout() {
        mBinding = ActivityStyleChoiceAllBinding.inflate(getLayoutInflater());
        return mBinding.getRoot();
    }

    @Override
    protected StyleChoiceAllPresenter getPresenter() {
        if (presenter == null) {
            presenter = new StyleChoiceAllPresenter(this, this);
        }
        return presenter;
    }

    @Override
    protected void onResume() {
        super.onResume();
        presenter.isBind(androidId);
    }

    @Override
    protected void initEventAndData() {
        initView();
        androidId = Settings.System.getString(getContentResolver(), Settings.System.ANDROID_ID);
        presenter.isBind(androidId);
    }

    private void initView() {
        mBinding.ivGirl.setOnClickListener(this);
        mBinding.ivLady.setOnClickListener(this);
        mBinding.ivMan.setOnClickListener(this);
        mBinding.ivBoy.setOnClickListener(this);
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.iv_girl:
                if (isBindStore) {
                    Intent mintent = new Intent(this, StyleSingleActivity.class);
                    mintent.putExtra("cateId", "4");
                    startActivity(mintent);
                } else {
                    Intent mintent = new Intent(this, BindStoreActivity.class);
                    startActivity(mintent);
                }
//                Intent mintents = new Intent(this, StyleSingleActivity.class);
//                mintents.putExtra("cateId", "1");
//                startActivity(mintents);
                break;
            case R.id.iv_lady:
                if (isBindStore) {
                    Intent mintent2 = new Intent(this, StyleSingleActivity.class);
                    mintent2.putExtra("cateId", "2");
                    startActivity(mintent2);
                } else {
                    Intent mintent = new Intent(this, BindStoreActivity.class);
                    startActivity(mintent);
                }

                break;
            case R.id.iv_man:
                if (isBindStore) {
                    Intent mintent3 = new Intent(this, StyleSingleActivity.class);
                    mintent3.putExtra("cateId", "1");
                    startActivity(mintent3);
                } else {
                    Intent mintent = new Intent(this, BindStoreActivity.class);
                    startActivity(mintent);
                }
                break;
            case R.id.iv_boy:
                if (isBindStore) {
                    Intent mintent4 = new Intent(this, StyleSingleActivity.class);
                    mintent4.putExtra("cateId", "3");
                    startActivity(mintent4);
                } else {
                    Intent mintent = new Intent(this, BindStoreActivity.class);
                    startActivity(mintent);
                }
                break;
        }
    }


    @Override
    public void onFailer(Throwable throwable) {

    }

    @Override
    public void onIsBind(AllBean info) {
        switch (info.getStatus()) {
            case 200:
                isBindStore = true;
                break;
            case 401: //未绑定
                isBindStore = false;
                break;
        }
    }
}
